package tuan.score;

import java.util.Map;

import org.w3c.dom.Node;

public class InAttrScore extends NodeScore {
	String attrName;
	Map<Object, Double> scoreRule;

	public InAttrScore(String attrName, Map<Object, Double> scoreRule)
			throws Exception {
		if (attrName == null || scoreRule == null) {
			throw new Exception("null arguments");
		}
		this.attrName = attrName;
		this.scoreRule = scoreRule;
	}

	@Override
	protected double getScore(Node node) {
		double defaultScore = 0.0;
		Object value = node.getUserData(attrName);
		if (scoreRule.containsKey(value)) {
			return scoreRule.get(value);
		} else {
			return defaultScore;
		}
	}

}
